package adminResource

import (
	"grpc.getaway.adminspro.padmins.com/internal/api/module/admin/container"
	"grpc.getaway.adminspro.padmins.com/internal/api/utils/rpc"
	pbAdmin "grpc.getaway.adminspro.padmins.com/pkg/proto/admin"
	"strconv"
)

func Add(c *container.Context) (interface{}, error) {
	pid, _ := strconv.ParseInt(c.Request.ParamsToString("pid", "0"), 10, 64)
	Type, _ := strconv.ParseInt(c.Request.ParamsToString("type", "1"), 10, 32)
	status, _ := strconv.ParseInt(c.Request.ParamsToString("status", "1"), 10, 32)
	weigh, _ := strconv.ParseInt(c.Request.ParamsToString("weigh", "0"), 10, 64)

	req := &pbAdmin.AdminResourceAddReq{
		AdminResource: &pbAdmin.AdminResource{
			Pid:      pid,
			Type:     int32(Type),
			Path:     c.Request.ParamsToString("path"),
			Resource: c.Request.ParamsToString("resource"),
			Title:    c.Request.ParamsToString("title"),
			Icon:     c.Request.ParamsToString("icon"),
			Remark:   c.Request.ParamsToString("remark"),
			Badge:    c.Request.ParamsToString("badge"),
			Weigh:    weigh,
			Status:   int32(status),
		},
	}
	resp, e := rpc.GetAdminClient().AdminResourceAdd(c.GetContext(), req)
	if e != nil {
		return resp, e
	}

	return map[string]map[string]interface{}{
		"row": {"id": resp.Id},
	}, nil
}
